﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CalculatorForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            comboBox1.Items.Add("+");
            comboBox1.Items.Add("-");
            comboBox1.Items.Add("*");
            comboBox1.Items.Add("/");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            double num1, num2, result;
            num1 = Convert.ToSingle(textBox1.Text);
            num2 = Convert.ToSingle(textBox2.Text);
            switch (comboBox1.Text) {
                case "+":
                    result = num1 + num2;
                    textBox3.Text = result.ToString();
                    break;
                case "-":
                    result = num1 - num2;
                    textBox3.Text = result.ToString();
                    break;
                case "*":
                    result = num1 * num2;
                    textBox3.Text = result.ToString();
                    break;
                case "/":
                    if (num2 == 0)
                    {
                        textBox3.Text = ("数据不合法");
                    }
                    else
                    {
                        result = num1 / num2;
                        textBox3.Text = result.ToString();
                    }
                    break;
            }
        }
    }
}
